package com.yx.gateway.route;

import org.springframework.cloud.gateway.route.RouteDefinition;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api")
public class RouteSettingController {

    @Resource
    private DynamicRouteServiceImpl dynamicRouteService;

    @PostMapping("/add")
    public String add(@RequestBody MyRouteDefinition myRouteDefinition) {
        try{
            dynamicRouteService.add(myRouteDefinition);
            return "success";
        }catch (Exception e){
            return "error";
        }
    }

    @PostMapping("delete")
    public String delete(String id) {
        try{
            dynamicRouteService.delete(id);
            return "success";
        }catch (Exception e){
            return "error";
        }
    }


}
